//
//  CXAlterItemButton.m
//  CXAlterButton
//
//  Created by chaox on 15/11/2.
//  Copyright © 2015年 chaox. All rights reserved.
//

#import "CXAlterItemButton.h"

@implementation CXAlterItemButton

- (instancetype)initWithImage :(UIImage *)image with:(NSString *)title;
{
    if (self = [super init]) {
        
        self.frame = CGRectMake(0, 0, 40, 12);
        
        [self setImage:image forState:UIControlStateNormal];
        self . titleLabel . textAlignment = NSTextAlignmentRight ;
        
        self . titleLabel . font =[ UIFont systemFontOfSize : 12.0 ];
        
        self . imageView . contentMode = UIViewContentModeScaleAspectFit ;
//        self.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [self setTitle:title forState:UIControlStateNormal];
//        [self setFont:[UIFont systemFontOfSize:12]];
        [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        
//        UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)
//        [self setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 30)];
//        [self setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
        
        
        [self addTarget:_delegate action:@selector(itemButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
        
        
    }
    return self;
}

//重写父类UIButton的方法

//更具button的rect设定并返回文本label的rect

- ( CGRect )titleRectForContentRect:( CGRect )contentRect

{
    
    CGFloat titleW = 30 ;
    
    CGFloat titleH = 12 ;
    
    CGFloat titleX = 12 ;
    
    CGFloat titleY = 0 ;
    
    contentRect = ( CGRect ){{titleX,titleY},{titleW,titleH}};
    
    return contentRect;
    
}

//更具button的rect设定并返回UIImageView的rect

- ( CGRect )imageRectForContentRect:( CGRect )contentRect

{
    
    CGFloat imageW = 12 ;
    
    CGFloat imageH = 12 ;
    
    CGFloat imageX = 2 ;
    
    CGFloat imageY = 0 ;
    
    contentRect = ( CGRect ){{imageX,imageY},{imageW,imageH}};
    
    return contentRect;
    
}

@end
